<template>
  <div>
    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
        </span>

      </a-table>
    </div>

    <pp-work-order-req-modal ref="modalForm" @ok="modalFormOk"></pp-work-order-req-modal>
  </div>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import PpWorkOrderReqModal from './modules/PpWorkOrderReqModal'
  import {getAction} from "@/api/manage";

  export default {
    name: 'PpWorkOrderReqTable',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      PpWorkOrderReqModal
    },
    props:{
      initQueryParam:{},
      initAddModel:{}
    },
    data () {
      return {
        description: '生产工单用料管理页面',
        // 表头
        columns: [
          {
            title:'物料号',
            align:"center",
            dataIndex: 'materialNo'
          },
          {
            title:'物料描述',
            align:"center",
            dataIndex: 'materialDesc'
          },
          {
            title:'单位',
            align:"center",
            dataIndex: 'unit'
          },
          {
            title:'单位数量',
            align:"center",
            dataIndex: 'perQty'
          },
          {
            title:'需求数量',
            align:"center",
            dataIndex: 'reqQty'
          },
          {
            title:'领用数量',
            align:"center",
            dataIndex: 'useQty'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
        ],
        url: {
          list: "/pp/workOrderReq/list",
          delete: "/pp/workOrderReq/delete",
          deleteBatch: "/pp/workOrderReq/deleteBatch",
          exportXlsUrl: "/pp/workOrderReq/exportXls",
          importExcelUrl: "pp/workOrderReq/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        Object.assign(this.queryParam, this.initQueryParam);
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
    }
  }
</script>
<style scoped>
.ant-card-body .table-operator {
  margin-bottom: 0px;
}
</style>